home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17178 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  42 lines

  1. Newsgroups: comp.lang.c,comp.lang.c++
  2. Path: newsfeed.internetmci.com!miwok!linex1!news
  3. From: mfried@linex.com (Marty Fried)
  4. Subject: Re: Q:Hex to Decimal?
  5. X-Nntp-Posting-Host: sp100.linex.com
  6. Message-ID: <3170908a.11774229@news.linex.com>
  7. Sender: news@linex1.linex.com
  8. Organization: Cirrius Cybernetics Corp
  9. X-Newsreader: Forte Agent .99e/32.209
  10. References: <316D2289.4759@tricon.net>
  11. Date: Sun, 14 Apr 1996 05:50:20 GMT
  12.  
  13. Once upon a time (OK, it was Thu, 11 Apr 1996 11:17:29 -0400), Thomas
  14. A Cooper <tacooper@tricon.net> wrote:
  15.  
  16. >I saw in a magazine a simple function to convert a HEX string to an 
  17. >integer:
  18. >
  19. >long int FAR PASCAL hex2int(char far *s)
  20. >{
  21. >     return strtol(s,NULL,16);
  22. >}
  23. >
  24. > I'm struggling with the reverse situation, a function to convert an 
  25. >integer into a HEX string. Anybody got any ideas?? Thanks in advance for 
  26. >your help.
  27.  
  28. Have you tried something like:
  29. void int2hex(LPSTR s, int num)
  30. {
  31.     sprintf(s, "%x", num);
  32. )
  33.  
  34. I guess there's a C++ stream class you could use, but I haven't gotten
  35. around to learning that yet.
  36.  
  37.  
  38. _______________________________________________________
  39. Marty Fried - mfried@linex.com     Press Enter to Exit
  40. San Anselmo, CA                           -NT message
  41. (MSVC4 + MFC) && (Win95 || NT);             
  42.